function showDialog(title,msg) {
	$("#myModal").find(".modal-header h3").html(title);
    $("#myModal").find(".modal-body p").html(msg);
    $("#myModal").modal('show');
    
    //setTimeout(function(){
    //    $("#myModal").attr('class','modal hide');
    //},4500);
}

function keydown(e)
{
    var e = e||event;
    var currKey = e.keyCode||e.which||e.charCode;
    if(currKey == 13)
    {
        checkLogin();
    }
}

function checkLogin(){
    var username = $("input[name='userName']").val();
    var password = $("input[name='password']").val();
    if ($.trim(username) == "" ||　$.trim(password) == "") {
        showDialog("登陆信息", "<span style='color:red;'>请输入帐号和密码！</span>");
        return false;
    }

    $.ajax({    
        url:'/Account/Login',
        data: {
            username : username,
            password : password
        },
        type:'post',   
        success:function(data) {
            if (data.IsSuccess) {
                window.location.href="/home/index";
            }else{
                showDialog("登陆信息","<span style='color:red;'>"+data.ErrorMessage+"</span>");
            }
        },    
        error: function () {
                showDialog("登陆信息","<span style='color:red;'>抱歉，系统错误，登录失败，请联系管理员！</span>");
        }
    });
}

function validatePwd(str){   
    if(str.length!=0){    
        reg=/^[A-Za-z]+[0-9]+[A-Za-z0-9]*|[0-9]+[A-Za-z]+[A-Za-z0-9]*$/;     
        if(!reg.test(str)){    
            return false;  
        } else {
            return true;
        }   
    } 

    return false;    
}


$(document).ready(function(){

	var login = $('#loginform');
	var recover = $('#recoverform');
	var speed = 400;



    
    if($.browser.msie == true && $.browser.version.slice(0,3) < 10) {
        $('input[placeholder]').each(function(){ 
	        var input = $(this);       
	       
	        $(input).val(input.attr('placeholder'));
	               
	        $(input).focus(function(){
	             if (input.val() == input.attr('placeholder')) {
	                 input.val('');
	             }
	        });
	       
	        $(input).blur(function(){
	            if (input.val() == '' || input.val() == input.attr('placeholder')) {
	                input.val(input.attr('placeholder'));
	            }
	        });
	    });    
    }

    $("#modelClose").click(function(){
        $("#myModal").attr('class','modal hide');
    });
    
});